package com.langsin.zangtingqiang.mapper;

import com.langsin.bean.Worker;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;


import java.io.InputStream;

public class Test {
    SqlSession sqlSession = null;

    @org.junit.Test
    public void test01(){
        //根据条件更新worker
        Worker worker=new Worker();
        worker.setWid("50f14e17-5e5d-11e9-9dc0-28d244d68b7c");
        worker.setAge(50);
        worker.setWname("过儿");

        WorkerMapper workerMapper = sqlSession.getMapper(WorkerMapper.class);
        int i = workerMapper.updateWorker(worker);
        System.out.println(i);
    }



    //每次单元测试类之前执行
    @Before
    public void before() throws Exception {
        //读取配置文件
        InputStream stream = Resources.getResourceAsStream("mybatis.xml");
        //工厂
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory sqlSessionFactory = builder.build(stream);
        //获取一个会话（连接）默认不提交
        sqlSession = sqlSessionFactory.openSession();
    }

    //每次单元测试类之后执行
    @After
    public void after() throws Exception {
        sqlSession.commit();
        sqlSession.close();
    }
}
